<%include pub/admin_head.html%>
    </head>
    <body>
        <!-- Page Container -->
        <div class="page-container">
            <%include pub/admin_nav.html%>
            <!-- Page Content -->
            <div class="page-content">
                <%include pub/admin_top.html%>
                <div class="page-inner">
                    <div class="page-title">
                        <h3 class="breadcrumb-header">所有作品</h3>
                    </div>
                    <div id="main-wrapper">
                        <div class="col-md-12">
                            <a href="/admin/works" class="btn btn-success" >搜索某个作品</a>
                            <a href="javascript:;" class="btn btn-success" data-toggle="modal" data-target="#userworksModal">搜索某个作者的作品</a>
                            <input type="hidden" value="<%= pagecount%>" id="compagecount">
                            <input type="hidden" value="<%= compageid%>" id="compageid">
                            <%if(username){%>
                            <div style="margin: 10px 0">
                                当前搜索用户账号：<%= username%>；<a href="/admin/workslist/1?user=" style="color: #0070E0"> 返回查看全部作品>></a>
                            </div>
                            <%}%>  
                            <%if(data && data.length > 0){%>
                            <table class="table" style="margin-top: 10px;">
                                <thead>
                                    <tr>
                                        <th>作品ID</th>
                                        <th>作品名称</th>
                                        <th>作者昵称</th>
                                        <th>作者账号</th>
                                        <th>发布时间</th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tbody>
                                <%for(let i = 0; i < data.length; i++){%>
                                <tr>
                                    <td><%= data[i]._id %></td>
                                    <td><%= data[i].title %></td>
                                    <td><%= data[i].user.nickname %></td>
                                    <td><%= data[i].user.username %></td>
                                    <td><%= data[i].time%></td>
                                    <td><a href="/works/content/1/<%- data[i]._id%>?released=<%- data[i]._id %>" target="_blank">查看</a> | <a href="/released/scratch/<%- data[i].worksid %>" download="<%- data[i].title %>.sb3" class="blue">下载</a> | <a href="javascript:;" class="red works-delete-btn" wid="<%- data[i]._id %>">删除</a></td>
                                </tr>
                                <%}%>   
                                </tbody>
                            </table>
                            <%}else{%>
                            <p style="margin-top: 10px;"> 暂无数据</p>
                            <%}%>   
                        </div>
                        <div id="work-pagination" class="pager row"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade bs-example-modal-sm" id="userworksModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="mySmallModalLabel">搜索某个作者全部作品</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>请输入作者账号</label>
                            <input type="text" class="form-control" id="works-username"/>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success" id="search-user-works">开始搜索</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- Javascripts -->
        <%include pub/admin_foot.html%>
        <script type="text/javascript">
        $(function(){
            var countnums = $('#compagecount').val();
            var currentPage = parseInt($('#compageid').val());
            if(countnums >  29 ){
                var total = Math.ceil(countnums/30);
                var prev = currentPage -1;
                var next = currentPage +1;
                $.jqPaginator('#work-pagination', {
                    totalPages: total,
                    visiblePages:5,
                    currentPage:currentPage,
                    page: '<li class="page"><a href="/admin/workslist/{{page}}?user=<%= username%>">{{page}}</a></li>',
                });
            }
        });
        $('#search-user-works').click(function(){
            var _userName = $('#works-username').val();
            if(_userName){
                window.location.href = '/admin/workslist/1?user='+_userName
            }else{
                alert('请输入作者账号')
            }
        })
        </script>
    </body>
</html>